/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dafe.partyband.mediaplayer;

import java.util.Map;

/**
 *
 * @author dafe
 */
public final class JavaZoomUtils {
    
    public static int obtainDuration(Object stream, Map properties) {
        Long durationMicro = (Long)properties.get("duration");
        Integer duration = durationMicro != null ? Math.round(durationMicro / 1000000) : null;
        Float fps = (Float)properties.get("audio.framerate.fps");
        if (fps == null) {
            fps = (Float)properties.get("mp3.framerate.fps");
        }
        Integer fsize = (Integer)properties.get("audio.framesize.bytes");
        if (fsize == null) {
            fsize = (Integer)properties.get("mp3.framesize.bytes");
        }
        if (duration == null) {
            Integer length = (Integer)properties.get("audio.length.bytes");
            duration = Math.round(length / (fps * fsize));
        }
        
        return duration;
    }

}
